package com.ewili.x.special.task.quraz;

import com.ewili.framework.service.inter.MailService;
import com.ewili.x.special.service.data.inter.*;
import com.ewili.x.special.service.strategy.inter.StrategyService;
import com.ewili.x.special.vo.StrategyVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;

@Component
public class StrategyQuraz {

    @Autowired
    private HisRecordService hisRecordService;

    @Autowired
    private StrategyService strategyService;

    @Autowired
    private StockService stockService;

    @Autowired
    private TradableShareHoldersService tradableShareHoldersService;

    @Autowired
    private MailService mailService;

    @Autowired
    private ExecsService execsService;

    @Autowired
    private ValueService valueService;

    @Autowired
    private ResearchReportService researchReportService;

    //@Scheduled(cron = "0 0 20 * * ?") // 每晚8点执行
    public void downStrategy() {
        hisRecordService.spideHisRecord();
        List<StrategyVo> strategies = strategyService.newStockDownStrategy();
        String content = "股票自动筛选时间：" + new Date().toString() + "\n";
        for (StrategyVo strategyVo : strategies) {
            String strategyContent = strategyVo.getStockCode() + "          " + strategyVo.getMinPercent() + "%            " + strategyVo.getBuyDate() + "\n";
            content += strategyContent;
        }

        //String mailTo = ConfigUtils.getConfig("mailTo");
        String[] mails = {"439182066@qq.com", "378981649@qq.com"};
        mailService.sendSimpleMail(mails, "股票自动筛选时间" + new Date().toString(), content);
    }

    //@Scheduled(fixedDelay = 5000)
    public void doSpide() {
        //十大股东增减持，按季度计算
        //tradableShareHoldersService.spide163TradableShareHolder();

        //高管增减持
        execsService.spideExecs();

        //历史交易记录
        hisRecordService.spideHisRecord();

        //股票数据
        stockService.spideStock();

        //估值数据
        valueService.spideValue();

        //个股研究报告
        researchReportService.spideResearchReport();

        //市场高管增减持
        //http://utdata.eastmoney.com/api/data/get?st=tdate&sr=-1&p=2&ps=50&sty=ALL&token=28dfeb41d35cc81d84b4664d7c23c49f&var=xPDhYnyJ&filter=(type=%221%22)&type=GGSCTJ&rt=52262231

    }
}
